//
//  DisCoverThreeLoginViewController.m
//  随拍
//
//  Created by lanou3g on 16/1/19.
//  Copyright © 2016年 Ashoka. All rights reserved.
//

#import "DisCoverThreeLoginViewController.h"
#import "UMSocial.h"
#import "DisCoverYouJIManager.h"


@interface DisCoverThreeLoginViewController ()<UMSocialUIDelegate>

@property(nonatomic,strong)UMSocialAccountEntity *snsSinaAccount;

@property(nonatomic,strong)UMSocialAccountEntity *snsRenrenAccount;

@property(nonatomic,strong)UIView * aView;




@end

@implementation DisCoverThreeLoginViewController




- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.view.backgroundColor = [UIColor clearColor];
    
    
    
    
    
    self.aView = [[UIView alloc] initWithFrame:CGRectMake(0, 500, self.view.frame.size.width, self.view.frame.size.height - 500)];
    
    _aView.backgroundColor = [UIColor whiteColor];
    
    UIButton * SinaButton = [UIButton buttonWithType:UIButtonTypeSystem];
    SinaButton.backgroundColor = [UIColor blackColor];
    [SinaButton setTitle:@"新浪登陆" forState:UIControlStateNormal];
    SinaButton.frame = CGRectMake(20, 20, 80, 40);
    [SinaButton addTarget:self action:@selector(sinaButtonLogin:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    
    
    
    
    
    
    UIButton * Renren = [UIButton buttonWithType:UIButtonTypeSystem];
    Renren.backgroundColor = [UIColor blueColor];
    [Renren setTitle:@"人人" forState:UIControlStateNormal];
    Renren.frame = CGRectMake(120, 20, 80, 40);
    [Renren addTarget:self action:@selector(renrenButtonLogin:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    
    
    
    
    
    
    [_aView addSubview:SinaButton];
    [_aView addSubview:Renren];
    
    [self.view addSubview:_aView];
    
    
    
}


-(void)sinaButtonLogin:(UIButton *)sender{


        UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
    
        snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
    
            //          获取微博用户名、uid、token等
    
            if (response.responseCode == UMSResponseCodeSuccess) {
    
                self.snsSinaAccount= [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
    
                if ( _snsSinaAccount.userName != nil) {
                    
                    [_aView removeFromSuperview];
                    
                    [self.navigationController popViewControllerAnimated:YES];
                    
                    [DisCoverYouJIManager shareDisCoverYouJIManager].loginUserName = _snsSinaAccount.userName;
                    
                     NSLog(@"-----%@",[DisCoverYouJIManager shareDisCoverYouJIManager].loginUserName);
                    
                     [DisCoverYouJIManager shareDisCoverYouJIManager].loginUserPic = _snsSinaAccount.iconURL;
                    
                }
                
                    //[_delegate passValue:_snsSinaAccount.userName AndValuetwo:_snsSinaAccount.iconURL];
                
                
                
                
                NSLog(@"username is %@, uid is %@, token is %@ url is %@",_snsSinaAccount.userName,_snsSinaAccount.usid,_snsSinaAccount.accessToken,_snsSinaAccount.iconURL);
                
            }});
    
    
    
    
}


-(void)renrenButtonLogin:(UIButton *)sender{

    UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToRenren];
    
    snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
        
        //          获取微博用户名、uid、token等
        
        if (response.responseCode == UMSResponseCodeSuccess) {
            
            self.snsRenrenAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToRenren];
            
              if (_snsRenrenAccount.userName != nil) {
            
            [_aView removeFromSuperview];
            
            [self.navigationController popViewControllerAnimated:YES];
            
              }
            
            
            
            [DisCoverYouJIManager shareDisCoverYouJIManager].loginUserName = _snsRenrenAccount.userName;
            
            NSLog(@"-----%@",[DisCoverYouJIManager shareDisCoverYouJIManager].loginUserName);
            
            [DisCoverYouJIManager shareDisCoverYouJIManager].loginUserPic = _snsRenrenAccount.iconURL;
            
            
//            _snsRenrenAccount.userName = [DisCoverYouJIManager shareDisCoverYouJIManager].loginUserName;
//            
//           
//            
//            _snsRenrenAccount.iconURL = [DisCoverYouJIManager shareDisCoverYouJIManager].loginUserPic;
            
            
          //  [_delegate passValue:_snsRenrenAccount.userName AndValuetwo:_snsRenrenAccount.iconURL];
            

            
            NSLog(@"username is %@, uid is %@, token is %@ url is %@",_snsRenrenAccount.userName,_snsRenrenAccount.usid,_snsRenrenAccount.accessToken,_snsRenrenAccount.iconURL);
            
        }});
    
  

}













- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
